import {
  exportUrl,
  downloadTemplateUrl,
  getStatusList,
} from "@/api/materialStation/mesMaterialStationType";
import excelUpload from "@/components/excel-upload/excelUpload";
import url from "@/axios/url";
const { mesUrl } = url();

// 列表头按钮配置
export const operateList = {
  data () {
    const _this = this;
    return {
      operateList: [
        {
          name: $i18n.t("common.export"),
          type: "primary",
          icon: "el-icon-download",
          handleName: "export", //点击时返回的标识
          url: exportUrl,
          //auth: "auth:operlog:export", //权限字段
        },
        {
          name: $i18n.t("common.add"),
          type: "primary",
          icon: "el-icon-circle-plus-outline",
          handleName: "add", //点击时返回的标识
        },
        {
          name: $i18n.t("common.delete"),
          type: "danger",
          icon: "el-icon-delete",
          handleName: "deleteBatch", //点击时返回的标识
          isMultiple: true, // isSingle 表示必须选择一项//isMultiple: true, // 表示必须多选
        },

        {
          // 导入文件
          render: (h, scope) => {
            // scope列表上选择的数据
            const uploadUrl = `${mesUrl}mesMaterialStationType/import`;
            return (
              <excelUpload
                action={uploadUrl}
                on={{
                  handleUploadError: (err) => {
                    // 失败的回调
                    console.log(err);
                  },
                  handleUploadSuccess: (res) => {
                    _this.$refs.eleTable.handleReset();
                    //成功 的回调
                  },
                }}
              />
            );
          },
        },
        {
          name: $i18n.t("common.downloadTemplate"),
          type: "success",
          icon: "el-icon-download",
          handleName: "template", //点击时返回的标识
          // url: downloadTemplateUrl,
        },
      ],
    };
  },
};
// 行末按钮配置
export const rowConfig = [
  {
    name: $i18n.t("common.edit"),
    type: "primary",
    class: "row-btn-primary",
    handleName: "edit", //点击时返回的标识
  },
  {
    name: $i18n.t("common.details"),
    type: "info",
    class: "row-btn-info",
    handleName: "detail", //点击时返回的标识
  },
  {
    name: $i18n.t("common.delete"),
    type: "danger",
    class: "row-btn-danger",
    handleName: "delete", //点击时返回的标识
  },
];
// 搜索条件配置
export const searchConfig = {
  inline: true,
  formDesc: {
    typeCode: {
      type: "input",
      label: $i18n.t("mesMaterialStationType.typeCode"),
    },
    typeName: {
      type: "input",
      label: $i18n.t("mesMaterialStationType.typeName"),
    },
    status: {
      type: "select",
      label: $i18n.t("mesMaterialStationType.status"),
      prop: {
        value: "value",
        text: "description",
      },
      options: async (data) => {
        const list = await getStatusList();
        return list.data.result;
      },
    },
  },
};
// 新增/删除表单配置
export const formDescDialog = {
  span: 24,
  disabled: false,
  isShowSubmitBtn: true,
  formDesc: {
    typeCode: {
      type: "input",
      label: $i18n.t("mesMaterialStationType.typeCode"),
      layout: 24,
      disabled: (data) => {
        return !!data.codeStrategy || !!data.id;
      },
      rules: [
        {
          max: 20,
          message: $i18n.t("mesMaterialStationType.maxLength20"),
          trigger: ["change", "blur"],
        },
      ],
    },
    typeName: {
      type: "input",
      label: $i18n.t("mesMaterialStationType.typeName"),
      layout: 24,
      required: true,
      rules: [
        {
          max: 50,
          message: $i18n.t("mesMaterialStationType.maxLength50"),
          trigger: ["change", "blur"],
        },
      ],
    },
    status: {
      type: "switch",
      label: $i18n.t("mesMaterialStationType.enable"),
      layout: 24,
      required: false,
      // 只能是0 和 1
      valueFormatter (labels) {
        return labels == "1" ? "1" : "0";
      },
      displayFormatter (labels) {
        return labels == "1" ? true : false;
      },
    },
    // remark: {
    //   type: "textarea",
    //   label: "备注",
    //   layout: 24,
    //   required: false,
    //   rules:[
    //     { max:200,message:'长度不可超过200', trigger: ["change", "blur"] }
    //   ]
    // },
  },
};
